import type { TableColumnData } from '@arco-design/web-vue'

import { useSearchUser } from '@/apis/user/composables'
import { Role } from '@/constants/role'

export function useStudentDrawerTable() {
  const columns = [
    {
      align: 'center',
      title: '学号/工号',
      dataIndex: 'username',
      width: 150,
      sortable: {
        sortDirections: ['ascend', 'descend']
      }
    },
    {
      align: 'center',
      title: '姓名',
      dataIndex: 'name',
      width: 150
    },
    {
      align: 'center',
      title: '权限',
      slotName: 'role',
      width: 220
    }
  ] as const satisfies TableColumnData[]

  const { data, isLoading } = useSearchUser({ role: Role.Student })

  return {
    isLoading,
    columns,
    students: data as Readonly<typeof data>
  }
}
